package 设计模式.Singleton;

/**
 * 同样也是在类中定义static变量的对象，并且直接初始化，不
 * 过是移到了静态内部类中，十分巧妙。既保证了线程的安全性，同时又满足了懒加载。
 * */
public class StaticInnerClass {
    private StaticInnerClass() {
    }
    public static StaticInnerClass getInstance() {
        return  InnerClass.sic;
    }
    private static class InnerClass{
        private static final StaticInnerClass sic = new StaticInnerClass();
    }

    public static void main(String[] args) {
        StaticInnerClass instance = StaticInnerClass.getInstance();
        StaticInnerClass instance1 = StaticInnerClass.getInstance();
        System.out.println(instance1==instance);
    }
}
